﻿using System.Windows;

namespace SHomeWorkshop.LunarPresentation.Commands
{
    public partial class Command
    {
        public static void Copy()
        {
            if (Globals.selectedEditor == null) return;
            if (Globals.selectedEditor.SelectedExpression == null) return;

            LunarPresentation.Expressions.Expression curEx
                = Globals.selectedEditor.SelectedExpression;

            if (curEx is Expressions.LeafPanel)
            {
                Command.CopyLeaf(); return;
            }

            if (curEx is Expressions.SubPanel)
            {
                MessageBox.Show("子面板不支持“复制”操作！", Globals.appName,
                    MessageBoxButton.OK, MessageBoxImage.Warning);
                return;//子面板不支持Copy。
            }

            if (curEx is Expressions.BaseText)
            {
                Expressions.BaseText curBt = curEx as Expressions.BaseText;
                if (curBt.IsCollapsed)
                {
                    MessageBox.Show("折叠的标题文本块不允许被复制。此外“剪切、粘贴、删除、平移、拖动、更改缩进、对齐、嵌入”等操作亦被禁止。",
                        Globals.appName, MessageBoxButton.OK, MessageBoxImage.Warning);
                    return;
                }
            }

            Clipboard.SetData(DataFormats.UnicodeText, curEx.XmlData.OuterXml);
        }
    }
}
